package com.city.parking.map;

import java.util.ArrayList;
import com.baidu.mapapi.map.offline.MKOLSearchRecord;

public class OfflineMapRemoteItemModel{
 
    private int cityID;
    private String cityName;
    private String packSize;
    private int downloadStatus; //0 - undownload; 1 - downloaded; 2 - downloading; 3 - download paused; more...
 
    private int itemType = -1; //10 - group header; 0 - country; 1 - province; 2 - city
    private boolean isInSubCityList = false;
    private MKOLSearchRecord listItem = null;
 
    public OfflineMapRemoteItemModel(String title) {
        super();
        this.cityName = title;
        this.itemType = 10;
    }
    
    public OfflineMapRemoteItemModel(MKOLSearchRecord listItem, int downloadStatus, boolean isInSubCityList) {
        super();
        this.cityID = listItem.cityID;
        this.cityName = listItem.cityName;
        this.packSize = formatDataSize(listItem.size);
        this.downloadStatus = downloadStatus;
        this.itemType = listItem.cityType;
        this.listItem = listItem;
        this.isInSubCityList = isInSubCityList;
    }
 
    public int getCityID() {
    	return this.cityID;
    }
    
    public String getCityName() {
    	return this.cityName;
    }
    
    public String getPackSize() {
    	return this.packSize;
    }
    
    public int getDownloadStatus() {
    	return this.downloadStatus;
    }
    
    public void setDownloadStatus(final int newDownloadStatus) {
    	this.downloadStatus = newDownloadStatus;
    }
    public ArrayList<MKOLSearchRecord> getSubCityList() {
       return this.listItem.childCities;
    }
    
    public int getSubCityListSize() {
       int retVal;
       
       if (this.listItem.cityType == 1) {
           retVal = this.listItem.childCities.size();
       } else {
           retVal = 0;
       }
       return retVal; 
    }
    
    public int getItemType() {
       return this.itemType;
    }
    
    public boolean isInSubList() {
       return this.isInSubCityList;
    }
    
    public String formatDataSize(int size) {
       String ret = "";
       if (size < (1024 * 1024)) {
           ret = String.format("%dK", size / 1024);
       } else {
           ret = String.format("%.1fM", size / (1024 * 1024.0));
       }
       return ret;
   }
}
